package com.hjh.netty.elect.demo4;

import com.hjh.netty.elect.util.DataConvertUtils;
import com.hjh.netty.elect.util.NumberDataConvertUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 实时测量数据 (子类=0x01，版本=1)
 * @author pyz
 *
 */
@Service("analysisRealtimeUpLoadDataService")
public class AnalysisRealtimeUpLoadDataService implements AnalysisUpLoadDataService{
	
	@Override
	public SubType1TypeVer1 analysisUpLoadData(String upLoadData) {
		int index = 0;
		SubType1TypeVer1 result = new SubType1TypeVer1();
		//A相电压  格式：float，单位：V
		String U1 = upLoadData.substring(index, index + 8);
		result.setU1(NumberDataConvertUtils.hexFloatString2decimalFloatString(U1));
		index += 8;
		//B相电压  格式：float，单位：V
		String U2 = upLoadData.substring(index, index + 8);
		result.setU2(NumberDataConvertUtils.hexFloatString2decimalFloatString(U2));
		index += 8;
		//C相电压  格式：float，单位：V
		String U3 = upLoadData.substring(index, index + 8);
		result.setU3(NumberDataConvertUtils.hexFloatString2decimalFloatString(U3));
		index += 8;
		//平均相电压  格式：float，单位：V
		String Uavg = upLoadData.substring(index, index + 8);
		result.setUavg(NumberDataConvertUtils.hexFloatString2decimalFloatString(Uavg));
		index += 8;
		//AB 线电压  格式：float，单位：V
		String U12 = upLoadData.substring(index, index + 8);
		result.setU12(NumberDataConvertUtils.hexFloatString2decimalFloatString(U12));
		index += 8;
		//BC 线电压  格式：float，单位：V
		String U23 = upLoadData.substring(index, index + 8);
		result.setU23(NumberDataConvertUtils.hexFloatString2decimalFloatString(U23));
		index += 8;
		//CA 线电压  格式：float，单位：V
		String U31 = upLoadData.substring(index, index + 8);
		result.setU31(NumberDataConvertUtils.hexFloatString2decimalFloatString(U31));
		index += 8;
		//平均线电压  格式：float，单位：V
		String Ullavg = upLoadData.substring(index, index + 8);
		result.setUllavg(NumberDataConvertUtils.hexFloatString2decimalFloatString(Ullavg));
		index += 8;
		//A相电流  格式：float，单位：A
		String I1 = upLoadData.substring(index, index + 8);
		result.setI1(NumberDataConvertUtils.hexFloatString2decimalFloatString(I1));
		index += 8;
		//B相电流  格式：float，单位：A
		String I2 = upLoadData.substring(index, index + 8);
		result.setI2(NumberDataConvertUtils.hexFloatString2decimalFloatString(I2));
		index += 8;
		//C相电流  格式：float，单位：A
		String I3 = upLoadData.substring(index, index + 8);
		result.setI3(NumberDataConvertUtils.hexFloatString2decimalFloatString(I3));
		index += 8;
		//平均相电流  格式：float，单位：A
		String Iavb = upLoadData.substring(index, index + 8);
		result.setIavb(NumberDataConvertUtils.hexFloatString2decimalFloatString(Iavb));
		index += 8;
		//A 相有功功率  格式：float，单位：W
		String Pa = upLoadData.substring(index, index + 8);
		result.setPa(NumberDataConvertUtils.hexFloatString2decimalFloatString(Pa));
		index += 8;
		//B 相有功功率  格式：float，单位：W
		String Pb = upLoadData.substring(index, index + 8);
		result.setPb(NumberDataConvertUtils.hexFloatString2decimalFloatString(Pb));
		index += 8;
		//C 相有功功率  格式：float，单位：W
		String Pc = upLoadData.substring(index, index + 8);
		result.setPc(NumberDataConvertUtils.hexFloatString2decimalFloatString(Pc));
		index += 8;
		//三相有功功率  格式：float，单位：W
		String P = upLoadData.substring(index, index + 8);
		result.setP(NumberDataConvertUtils.hexFloatString2decimalFloatString(P));
		index += 8;
		//A相无功功率  格式：float，单位：var
		String Q1 = upLoadData.substring(index, index + 8);
		result.setQ1(NumberDataConvertUtils.hexFloatString2decimalFloatString(Q1));
		index += 8;
		//B相无功功率  格式：float，单位：var
		String Q2 = upLoadData.substring(index, index + 8);
		result.setQ2(NumberDataConvertUtils.hexFloatString2decimalFloatString(Q2));
		index += 8;
		//C相无功功率  格式：float，单位：var
		String Q3 = upLoadData.substring(index, index + 8);
		result.setQ3(NumberDataConvertUtils.hexFloatString2decimalFloatString(Q3));
		index += 8;
		//三相总无功功率  格式：float，单位：var
		String Q = upLoadData.substring(index, index + 8);
		result.setQ(NumberDataConvertUtils.hexFloatString2decimalFloatString(Q));
		index += 8;
		//A相视在功率  格式：float，单位： VA
		String S1 = upLoadData.substring(index, index + 8);
		result.setS1(NumberDataConvertUtils.hexFloatString2decimalFloatString(S1));
		index += 8;
		//B相视在功率  格式：float，单位： VA
		String S2 = upLoadData.substring(index, index + 8);
		result.setS2(NumberDataConvertUtils.hexFloatString2decimalFloatString(S2));
		index += 8;
		//C相视在功率  格式：float，单位： VA
		String S3 = upLoadData.substring(index, index + 8);
		result.setS3(NumberDataConvertUtils.hexFloatString2decimalFloatString(S3));
		index += 8;
		//三相总视在功率  格式：float，单位：VA
		String S = upLoadData.substring(index, index + 8);
		result.setS(NumberDataConvertUtils.hexFloatString2decimalFloatString(S));
		index += 8;
		//A 相功率因数  格式：float，单位： 
		String PF1 = upLoadData.substring(index, index + 8);
		result.setPF1(NumberDataConvertUtils.hexFloatString2decimalFloatString(PF1));
		index += 8;
		//B 相功率因数  格式：float，单位： 
		String PF2 = upLoadData.substring(index, index + 8);
		result.setPF2(NumberDataConvertUtils.hexFloatString2decimalFloatString(PF2));
		index += 8;
		//B 相功率因数  格式：float，单位： 
		String PF3 = upLoadData.substring(index, index + 8);
		result.setPF3(NumberDataConvertUtils.hexFloatString2decimalFloatString(PF3));
		index += 8;
		//总功率因数  格式：float，单位：
		String PFavg = upLoadData.substring(index, index + 8);
		result.setPFavg(NumberDataConvertUtils.hexFloatString2decimalFloatString(PFavg));
		index += 8;
		//频率  格式：float，单位：
		String freq = upLoadData.substring(index, index + 8);
		result.setFreq(NumberDataConvertUtils.hexFloatString2decimalFloatString(freq));
		index += 8;
		//A/AB电压相位  格式：float，单位：°
		String U1Ang = upLoadData.substring(index, index + 8);
		result.setU1Ang(NumberDataConvertUtils.hexFloatString2decimalFloatString(U1Ang));
		index += 8;
		//B/BC电压相位  格式：float，单位：°
		String Ang = upLoadData.substring(index, index + 8);
		result.setAng(NumberDataConvertUtils.hexFloatString2decimalFloatString(Ang));
		index += 8;
		//C/CA电压相位  格式：float，单位：°
		String U3Ang = upLoadData.substring(index, index + 8);
		result.setU3Ang(NumberDataConvertUtils.hexFloatString2decimalFloatString(U3Ang));
		index += 8;
		//A相电流相位  格式：float，单位：0°
		String IaAng = upLoadData.substring(index, index + 8);
		result.setIaAng(NumberDataConvertUtils.hexFloatString2decimalFloatString(IaAng));
		index += 8;
		//B相电流相位  格式：float，单位：°
		String IbAng = upLoadData.substring(index, index + 8);
		result.setIbAng(NumberDataConvertUtils.hexFloatString2decimalFloatString(IbAng));
		index += 8;
		//C相电流相位  格式：float，单位：°
		String IcAng = upLoadData.substring(index, index + 8);
		result.setIcAng(NumberDataConvertUtils.hexFloatString2decimalFloatString(IcAng));
		index += 8;
		//计算中性线电流 Inc  格式：float，单位：A
		String In = upLoadData.substring(index, index + 8);
		result.setIn(NumberDataConvertUtils.hexFloatString2decimalFloatString(In));
		index += 8;
		//剩余电流IR  格式：float，单位：mA
		String IR = upLoadData.substring(index, index + 8);
		result.setIR(NumberDataConvertUtils.hexFloatString2decimalFloatString(IR));
		index += 8;
		//A 相基波功率因数  格式：float，单位：
		String dPF1 = upLoadData.substring(index, index + 8);
		result.setDPF1(NumberDataConvertUtils.hexFloatString2decimalFloatString(dPF1));
		index += 8;
		//B 相基波功率因数  格式：float，单位：
		String dPF2 = upLoadData.substring(index, index + 8);
		result.setDPF2(NumberDataConvertUtils.hexFloatString2decimalFloatString(dPF2));
		index += 8;
		//C 相基波功率因数  格式：float，单位：
		String dPF3 = upLoadData.substring(index, index + 8);
		result.setDPF3(NumberDataConvertUtils.hexFloatString2decimalFloatString(dPF3));
		index += 8;
		//总基波功率因数  格式：float，单位：
		String dPF = upLoadData.substring(index, index + 8);
		result.setDPF(NumberDataConvertUtils.hexFloatString2decimalFloatString(dPF));
		index += 8;
		//预留字段1  格式：float，单位：
		String pramas1 = upLoadData.substring(index, index + 8);
		result.setPramas1(NumberDataConvertUtils.hexFloatString2decimalFloatString(pramas1));
		index += 8;
		//预留字段2  格式：float，单位：
		String pramas2 = upLoadData.substring(index, index + 8);
		result.setPramas2(NumberDataConvertUtils.hexFloatString2decimalFloatString(pramas2));
		index += 8;
		//温度 1  格式：float，单位：℃
		String TC1 = upLoadData.substring(index, index + 8);
		result.setTC1(NumberDataConvertUtils.hexFloatString2decimalFloatString(TC1));
		index += 8;
		//温度 2  格式：float，单位：℃
		String TC2 = upLoadData.substring(index, index + 8);
		result.setTC2(NumberDataConvertUtils.hexFloatString2decimalFloatString(TC2));
		index += 8;
		//温度 3 格式：float，单位：℃
		String TC3 = upLoadData.substring(index, index + 8);
		result.setTC3(NumberDataConvertUtils.hexFloatString2decimalFloatString(TC3));
		index += 8;
		//温度 4  格式：float，单位：℃
		String TC4 = upLoadData.substring(index, index + 8);
		result.setTC4(NumberDataConvertUtils.hexFloatString2decimalFloatString(TC4));
		index += 8;
		//剩余电流报警状态  格式：uint16，单位：
		String IRalarmStatus = upLoadData.substring(index, index + 4);
		result.setIRalarmStatus(NumberDataConvertUtils.hexString2decimalInt(IRalarmStatus));
		index += 4;
		//温度报警状态  格式：uint16，单位：
		String TCalarmStatus = upLoadData.substring(index, index + 4);
		result.setTCalarmStatus(NumberDataConvertUtils.hexString2decimalInt(TCalarmStatus));
		index += 4;
		//DI状态  格式：uint16，单位：
		String DIStatus = upLoadData.substring(index, index + 4);
		result.setDIStatus(NumberDataConvertUtils.hexString2decimalInt(DIStatus));
		index += 4;
		//DI联动状态  格式：uint16，单位：
		String DILinkStatus = upLoadData.substring(index, index + 4);
		result.setDILinkStatus(NumberDataConvertUtils.hexString2decimalInt(DILinkStatus));
		index += 4;
		//DO状态  格式：uint16，单位：
		String DOStatus = upLoadData.substring(index, index + 4);
		result.setDOStatus(NumberDataConvertUtils.hexString2decimalInt(DOStatus));
		index += 4;
		//电流报警/预警状态  格式：uint16，单位：
		String IalarmStatus = upLoadData.substring(index, index + 4);
		result.setIalarmStatus(NumberDataConvertUtils.hexString2decimalInt(IalarmStatus));
		index += 4;
		//越限状态  格式：uint16，单位：
		String setpointStatus = upLoadData.substring(index, index + 4);
		result.setSetpointStatus(NumberDataConvertUtils.hexString2decimalInt(setpointStatus));
		index += 4;
		//接线自检状态  格式：uint16，单位：
		String selfCheckStatus = upLoadData.substring(index, index + 4);
		result.setSelfCheckStatus(NumberDataConvertUtils.hexString2decimalInt(selfCheckStatus));
		index += 4;
		//SOE 指针总数  格式：uint32，单位：
		String SOEpointer = upLoadData.substring(index, index + 8);
		result.setSOEpointer(NumberDataConvertUtils.hexString2decimalInt(SOEpointer));
		index += 8;
		//装置运行时间  格式：uint32，单位：0.1hour
		String OperatingTime = upLoadData.substring(index, index + 8);
		result.setOperatingTime(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(OperatingTime), new BigDecimal("0.1")));
		index += 8;
		//剩余电流自检状态  格式：uint16，单位：
		String IRCheckStatus = upLoadData.substring(index, index + 4);
		result.setIRCheckStatus(NumberDataConvertUtils.hexString2decimalInt(IRCheckStatus));
		index += 4;
		//温度自检状态  格式：uint16，单位：
		String TCCheckStatus = upLoadData.substring(index, index + 4);
		result.setTCCheckStatus(NumberDataConvertUtils.hexString2decimalInt(TCCheckStatus));
		index += 4;
		//总故障报警状态 格式：uint16，单位：
		String AllalarmStatus = upLoadData.substring(index, index + 4);
		result.setAllalarmStatus(NumberDataConvertUtils.hexString2decimalInt(AllalarmStatus));
		index += 4;
		
		return result;
	}

}
